home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / glibc108.zip / glibc108 / set-hooks.h < prev    next >
C/C++ Source or Header  |  1994-04-04  |  2KB  |  55 lines

  1. /* Macros for using symbol sets for running lists of functions.
  2. Copyright (C) 1994 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4.  
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Library General Public License as
  7. published by the Free Software Foundation; either version 2 of the
  8. License, or (at your option) any later version.
  9.  
  10. The GNU C Library is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13. Library General Public License for more details.
  14.  
  15. You should have received a copy of the GNU Library General Public
  16. License along with the GNU C Library; see the file COPYING.LIB.  If
  17. not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  18. Cambridge, MA 02139, USA.  */
  19.  
  20. #ifndef _SET_HOOKS_H
  21.  
  22. #define __need_size_t
  23. #include <stddef.h>
  24. #include <sys/cdefs.h>
  25.  
  26. /* Define a hook variable called NAME.  Functions put on this hook take
  27.    arguments described by PROTO.  Use `text_set_element (NAME, FUNCTION)'
  28.    from gnu-stabs.h to add a function to the hook.  */
  29.  
  30. #define DEFINE_HOOK(NAME, PROTO) \
  31. const struct                                      \
  32.   {                                          \
  33.     size_t n;                                      \
  34.     void (*fn[0]) __P (PROTO);                              \
  35.   } NAME
  36.  
  37. /* Run all the functions hooked on the set called NAME.
  38.    Each function is called like this: `function ARGS'.  */
  39.  
  40. #define RUN_HOOK(NAME, ARGS) \
  41. do {                                          \
  42.   size_t i;                                      \
  43.   for (i = 0; i < NAME.n; ++i)                              \
  44.     (*NAME.fn[i]) ARGS;                                  \
  45. } while (0)
  46.  
  47. /* Define a hook variable with NAME and PROTO, and a function called RUNNER
  48.    which calls each function on the hook in turn, with ARGS.  */
  49.  
  50. #define DEFINE_HOOK_RUNNER(name, runner, proto, args) \
  51. DEFINE_HOOK (name, proto); void runner proto { RUN_HOOK (name, args); }
  52.  
  53.  
  54. #endif
  55.